package com.example.batterynotification;

import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.IBinder;
import android.util.Log;
import android.widget.Toast;

public class notificationSoundService extends Service {
	MediaPlayer myPlayer;

	@Override
	public void onCreate() {
		Log.i("NS", "on create");
		super.onCreate();
	}

	@Override
	public int onStartCommand(Intent intent, int flags, int startId) {
		Log.i("NS", "onStartCommand notificationSoundManager");
		if (intent != null && intent.getExtras() != null) 
		{
				Log.i("NS", "onStartCommand passed the condition");
				try{
				myPlayer = MediaPlayer.create(this,
						Uri.parse(intent.getExtras().getString("sound")));
				myPlayer.setLooping(false);
				}
				catch(Exception ex){
					Log.i("NS", ex.toString());
				}
				Log.i("NS", "media player created with "
						+ intent.getExtras().getString("sound"));
				try {
					myPlayer.start();
				} catch (Exception ex) {
					Log.i("NS", "failed ??");
				}
			
		}

		return super.onStartCommand(intent, flags, startId);
	}

	@Override
	public void onDestroy() {
		Log.i("NS", "on destroy");
		try{
		myPlayer.stop();
		}
		catch(Exception ex)
		{
			
		}
		super.onDestroy();
	}

	@Override
	public IBinder onBind(Intent intent) {
		return null;
	}

}
